<template>
    <Layout>
        <div>
            <el-card class="box-card">
                <p>
                    <el-descriptions title="创建广西标准化协会团体标准发布统计表列表" :column="1" border>
                    </el-descriptions>
                </p>
                <el-form style=" width: 50%;" :model="ruleForm" :rules="rules" ref="ruleForm" label-width="200px"
                    class="demo-ruleForm">
                    <el-form-item label="序号">
                        <span>{{ ruleForm.id }}</span>
                    </el-form-item>
                    <el-form-item label="标准类型" prop="projectNumber">
                        <el-input v-model="ruleForm.projectNumber"></el-input>
                    </el-form-item>
                    <el-form-item label="标准代号" prop="standardCode">
                        <el-input v-model="ruleForm.standardCode"></el-input>
                    </el-form-item>
                    <el-form-item label="标准名称" prop="standardName">
                        <el-input v-model="ruleForm.standardName"></el-input>
                    </el-form-item>

                    <el-form-item label="发布日期" prop="releaseDate">
                        <el-input v-model="ruleForm.releaseDate"></el-input>
                    </el-form-item>
                    <el-form-item label="实施日期" prop="updateTime">
                        <el-input v-model="ruleForm.updateTime"></el-input>
                    </el-form-item>
                    <el-form-item label="提出单位" prop="proposedUnit">
                        <el-input v-model="ruleForm.proposedUnit"></el-input>
                    </el-form-item>
                    <el-form-item label="起草单位" prop="draftingUnit">
                        <el-input v-model="ruleForm.draftingUnit"></el-input>
                    </el-form-item>
                    <el-form-item>
                        <el-button type="primary" @click="submitForm('ruleForm')">立即修改</el-button>
                        <el-button @click="resetForm">返回</el-button>
                    </el-form-item>
                </el-form>

            </el-card>


        </div>
    </Layout>
</template>
<script>
import Layout from '@/components/Layout.vue';
import axios from 'axios';
export default {
    data() {
        return {

            ruleForm: {
                id: "",
                projectNumber: "",
                standardCode: "",
                standardName: "",
                releaseDate: "",
                updateTime: "",
                proposedUnit: "",
                draftingUnit: ''
            },
            rules: {
                projectNumber: [
                    { required: true, message: '请输入立项编号', trigger: 'blur' },

                ],
                standardName: [
                    { required: true, message: '请输入标准名称', trigger: 'blur' },

                ],
                standardCode: [
                    { required: true, message: '请输入标准代号', trigger: 'blur' },

                ],
            },
        }
    },
    methods: {
        submitForm(formName) {
            this.$refs[formName].validate((valid) => {
                if (valid) {
                    axios({
                        url: "http://43.143.166.235:8090/publish/inser",
                        method: "post",
                        data: {
                            "id": this.total + 1,
                            "projectNumber": this.ruleForm.projectNumber,
                            "standardCode": this.ruleForm.standardCode,
                            "standardName": this.ruleForm.standardName,
                            "releaseDate": this.ruleForm.releaseDate,
                            "updateTime": this.ruleForm.updateTime,
                            "proposedUnit": this.ruleForm.proposedUnit,
                            "groupProposing": this.ruleForm.groupProposing,
                            "draftingUnit": this.ruleForm.draftingUnit
                        }
                    }).then(res => {
                        console.log(res)
                    })
                    alert('增加成功!');
                    this.$router.push({
                        name: 'program'
                    })
                } else {
                    console.log('error submit!!');
                    return false;
                }
            });
        },

    },
    created() {
        const { cid } = this.$route.params
        if (cid != null) {
            axios({
                url: "http://43.143.166.235:8090/publish/select?id=" + cid
            }).then(res => {
                console.log("aaaaaaa", res)
                this.ruleForm.id = res.data.id
                this.ruleForm.projectNumber = res.data.projectNumber
                this.ruleForm.standardCode = res.data.standardCode
                this.ruleForm.standardName = res.data.standardName
                this.ruleForm.releaseDate = res.data.releaseDate
                this.ruleForm.updateTime = res.data.updateTime
                this.ruleForm.proposedUnit = res.data.proposedUnit
                this.ruleForm.draftingUnit = res.data.draftingUnit

            })
        } else {
            axios({
                url: "http://43.143.166.235:8090/publish/home?page=" + 1
            }).then(res => {
                this.ruleForm.id = res.data.data.total + 1
            })
        }
    },
    components: {
        Layout
    }
}
</script>
<style>   .box-card {
       height: calc(100vh - 60px);
   }
</style>